package com.ruoyi.userr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.userr.domain.CategoryTop;
import com.ruoyi.userr.service.ICategoryTopService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一级菜谱分类（带图标等专属字段）Controller
 * 
 * @author ruoyi
 * @date 2025-08-19
 */
@RestController
@Controller("userCategoryTopController")
@RequestMapping("/system/top")
public class CategoryTopController extends BaseController
{
    @Autowired
    private ICategoryTopService categoryTopService;

    /**
     * 查询一级菜谱分类（带图标等专属字段）列表
     */
    //@PreAuthorize("@ss.hasPermi('system:top:list')")
    @GetMapping("/list")
    public TableDataInfo list(CategoryTop categoryTop)
    {
        startPage();
        List<CategoryTop> list = categoryTopService.selectCategoryTopList(categoryTop);
        return getDataTable(list);
    }

    /**
     * 导出一级菜谱分类（带图标等专属字段）列表
     */
    @PreAuthorize("@ss.hasPermi('system:top:export')")
    @Log(title = "一级菜谱分类（带图标等专属字段）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CategoryTop categoryTop)
    {
        List<CategoryTop> list = categoryTopService.selectCategoryTopList(categoryTop);
        ExcelUtil<CategoryTop> util = new ExcelUtil<CategoryTop>(CategoryTop.class);
        util.exportExcel(response, list, "一级菜谱分类（带图标等专属字段）数据");
    }

    /**
     * 获取一级菜谱分类（带图标等专属字段）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:top:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(categoryTopService.selectCategoryTopById(id));
    }

    /**
     * 新增一级菜谱分类（带图标等专属字段）
     */
    @PreAuthorize("@ss.hasPermi('system:top:add')")
    @Log(title = "一级菜谱分类（带图标等专属字段）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CategoryTop categoryTop)
    {
        return toAjax(categoryTopService.insertCategoryTop(categoryTop));
    }

    /**
     * 修改一级菜谱分类（带图标等专属字段）
     */
    @PreAuthorize("@ss.hasPermi('system:top:edit')")
    @Log(title = "一级菜谱分类（带图标等专属字段）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CategoryTop categoryTop)
    {
        return toAjax(categoryTopService.updateCategoryTop(categoryTop));
    }

    /**
     * 删除一级菜谱分类（带图标等专属字段）
     */
    @PreAuthorize("@ss.hasPermi('system:top:remove')")
    @Log(title = "一级菜谱分类（带图标等专属字段）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(categoryTopService.deleteCategoryTopByIds(ids));
    }
}
